import React from 'react';

import {Button, Input, Select} from 'antd';
import ObjectList from '../../components/ObjectList';

import router from '../../../utils/routerDecorator';
import {get, post} from '../../../logic/api';

const Operation = ObjectList.Operation;
const InputEx = ObjectList.InputEx;
const SelectEx = ObjectList.SelectEx;

export default class User extends React.Component {

  state = {
  }

  async componentWillMount(){
  }

  dataIndex = [{
    name:'name',
    subtitle:'用户名'
  },{
    name:'sex',
    subtitle:'性别',
    type:'select',
    options:[{
      value:'male',
      text:'男'
    },{
      value:'female',
      text:'女'
    }]
  },{
    name:'email',
    subtitle:'邮箱'
  },{
    name:'wechat',
    subtitle:'微信'
  },{
    name:'avatar',
    subtitle:'头像',
    type:'img'
  }];

  
  async onOk(r, f){
    console.log(r, f);

    var ret = await post('/admin/user/updateInfo', {
      id:r.id,
      name:f.name,
      sex:f.sex,
      email:f.email,
      wechat:f.wechat,
      avatar:f.avatar
    });

    return ret;
  }


  render(){

    return <Operation 
      text = "修改信息" 
      record = {this.props.record}
      dataIndex = {this.dataIndex}
      fetchData = {async ()=>{
        return await get('/admin/user/userinfo/' + this.props.record.id);
      }} 
      onOk = {async (r, f)=>{
        return await this.onOk(r, f);
      }}>
    </Operation>
  }
}